/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var beautifulSubsets = function (nums, k) {
  let arr = [],res = []
    count = 0
  nums.sort((a, b) => a - b)

  bc(0)
  function bc(index) {
    if (check(arr, nums[index])) {
      res.push([...arr])
      count++
    }

    for (let i = index; i < nums.length; i++) {
      arr.push(nums[i])
      bc(i + 1)
      arr.pop()
    }
  }

  function check(arr, num) {
    for (let i = 0; i < arr.length; i++) {
      if (Math.abs(arr[i] - num) > k) return false
    }

    return true
  }
let a = count
  return count
}

beautifulSubsets([2,4,6],4)